<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>问卷调查</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="apple-mobile-web-app-status-bar-style" content="default"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="format-detection" content="telephone=no"/>
    <link href="${s.base}/mobile/css/weui.min.css" rel="stylesheet"/>
    <link href="${s.base}/mobile/css/jquery-weui.min.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/cy-style.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/indexnew.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/weChat.css" rel="stylesheet">
    <script type="text/javascript" src="${s.base}/mobile/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="${s.base}/mobile/js/fontSize.js"></script>
</head>
<body>

<div class="weui-pull-to-refresh__layer">
    <div class="pull-to-refresh__arrow"></div> <!-- 上下拉动的时候显示的箭头 -->
    <div class="pull-to-refresh__preloader"></div> <!-- 正在刷新的菊花 -->
    <div class="down">下拉刷新</div><!-- 下拉过程显示的文案 -->
    <div class="up">释放刷新</div><!-- 下拉超过50px显示的文案 -->
    <div class="refresh">正在刷新...</div><!-- 正在刷新时显示的文案 -->
</div>

<div class="main-ctn">
    <div class="question-list">
        <ul>

        </ul>
    </div>
</div>

<div class="weui-loadmore">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>

<div class="nodate-ctn" style="display: none">
    <p>
        <img src="${s.base}/mobile/images/nodates.png"><br>
        <span>暂无数据</span>
    </p>
</div>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-weui.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/fastclick.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/common.js"></script>
<script type="text/javascript">
    var page = 1;
    var limit = 10;
    var loading = false;
    var applyId = '${applyId}';
    var token = '${token}';
    $('.weui-loadmore').hide();

    $(".nodate-ctn").css("height", document.body.scrollHeight - 50);
    $(function () {
        FastClick.attach(document.body);
        initData('1');
        initListener();
    });


    function initData(flag) {
        if (flag === '1') {
            $(document.body).infinite(100);
        }
        $.fn.doPost('/phone/question/jsonList', {pageStatus: '2',applyId:applyId, pageNum: page, pageSize: limit,token:token}, function (result) {
            if (result.code === 0) {
                if (!result.hasNextPage) {
                    $(document.body).destroyInfinite();
                }
                if (flag === '1') {
                    $('.question-list ul').html('');
                    $(document.body).pullToRefreshDone();
                } else if (flag === '2') {
                    loading = false;
                    $(".weui-loadmore").hide();
                }
                postData(result.data);
            } else {
                $.toast('获取数据失败', "text");
            }
        });
    }

    function initListener() {
        //初始化下拉刷新
        $(document.body).pullToRefresh();
        $(document.body).on("pull-to-refresh", function () {
            page = 1;
            limit = 10;
            initData('1');
        });

        //初始化滚动加载
        $(document.body).infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            $('.weui-loadmore').show();
            page++;
            initData('2');
        });
    }

    function postData(data) {
        var str = '';
        if (data != null && data.length > 0) {
            for (var i = 0; i < data.length; i++) {
                var e = data[i];
                str += '<li class="clearfix" onclick="goQuestionnaire(\''+e.id+'\',\''+e.status+'\',\''+e.startTime+'\')">\
                    <div class="wjicon"><img src="${s.base}/mobile/images/wjicon.png"></div>\
                    <div class="wjtitle "><div class="div-tit">'+e.title+'</div></div>';
                // 状态
                if(e.status == "2") {
                    str+='<div class="wjstatue bg-orange-bar">未开始</div>';
                } else if(e.status == "3"){
                    // 发布中判断是否已提交
                    if (e.userStatus == '1') {
                        str+='<div class="wjstatue bg-blue-bar">已提交</div>';
                    } else {
                        str+='<div class="wjstatue bg-blue-bar">发布中</div>';
                    }
                } else if(e.status == "4"){
                    str+='<div class="wjstatue bg-grey-bar">已结束</div>';
                }
                str += '</li>';
            }
        }
        if (isBlank(str)) {
            $('.nodate-ctn').show();
            $('.question-list ul').html(str);
        } else {
            $('.question-list ul').html(str);
            // $('.question-list ul').append(str);
        }
    }

    function goQuestionnaire(id, status,startTime){
        // 时间
        if(status == 2) {
            $.toast('开始时间：'+startTime, "text");
            return false;
        }
        window.location.href = "/phone/question/questionEdit?questionId=" + id + "&token=${token}&applyId=${applyId}";
    }
</script>
</body>
</html>
